package com.zmn.oms.services.impl.track;

import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
import com.zmn.oms.model.entity.track.OrderTrack;
import com.zmn.oms.model.entity.track.OrderTrackQuery;
import com.zmn.oms.persistence.interfaces.track.OrderTrackDao;
import com.zmn.oms.services.interfaces.track.OrderTrackService;
import io.shardingsphere.api.HintManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 类描述：跟单实现类
 *
 * @author heciqi
 * @date 2018/11/26 22:07
 */
@Service
@Deprecated
public class OrderTrackServiceImpl implements OrderTrackService {
	@Autowired
	private OrderTrackDao orderTrackDao;

	@ReadOnlyConnection
	@Override
	public OrderTrack findById(Long trackId) {
		return orderTrackDao.findById(trackId);
	}

	@Override
	public List<OrderTrack> listOrderTrackByOrderIdList(List<Long> orderIdList) {
		try (HintManager hintManager = HintManager.getInstance()) {
			hintManager.setMasterRouteOnly();
			return orderTrackDao.listOrderTrackByOrderIdList(orderIdList);
		}
	}

	@Override
	public List<OrderTrack> listOrderTrackByWorkId(Long orderId, Long workId) {
		return orderTrackDao.listOrderTrackByWorkId(orderId, workId);
	}

	@Override
	public List<OrderTrack> listOrderTrackByWorkIdSrcMaster(Long orderId, Long workId) {
		try (HintManager hintManager = HintManager.getInstance()) {
			hintManager.setMasterRouteOnly();
			return orderTrackDao.listOrderTrackByWorkId(orderId, workId);
		}
	}

	/**
	 * 数量查询
	 * @param query
	 * @return
	 */
	@Override
	public Integer countByQuery(OrderTrackQuery query) {
		return orderTrackDao.countByQuery(query);
	}

	/**
	 * 新增跟单List
	 * @param orderTrack
	 * @return
	 */
	@Override
	public Integer insertTrack(OrderTrack orderTrack) {
		return orderTrackDao.insertOrderTrack(orderTrack);
	}

	/**
	 * 新增跟单
	 * @param orderTrackList
	 * @return
	 */
	@Override
	public Integer insertTrackList(List<OrderTrack> orderTrackList) {
		if (CollectionUtils.isEmpty(orderTrackList)) {
			return 0;
		}
		return orderTrackDao.insertOrderTrackList(orderTrackList);
	}

	/**
	 * 新增完成跟单
	 * @param orderTrackList
	 * @return
	 */
	@Override
	public Integer insertCompleteTrackList(List<OrderTrack> orderTrackList) {
		if (CollectionUtils.isEmpty(orderTrackList)) {
			return 0;
		}
		return orderTrackDao.insertCompleteOrderTrackList(orderTrackList);
	}

	/**
	 * 修改跟单结果
	 *
	 * @param orderTrack
	 * @return
	 */
	@Override
	public Integer updateResultTrack(OrderTrack orderTrack) {
		return orderTrackDao.updateOrderTrack(orderTrack);
	}

	/**
	 * 根据跟单id集合删除
	 * @param trackIdList
	 * @return
	 */
	@Override
	public Integer deleteByTrackIdList(List<Long> trackIdList) {
		return orderTrackDao.deleteByTrackIdList(trackIdList);
	}
}
